From fe53e05dbfa863e61c11cc31c52ef6a7626419d0 Mon Sep 17 00:00:00 2001 From: Ryan Quattlebaum Date: Fri, 18 Mar 2016 12:00:22 -0400 Subject: [PATCH] Move suggestion logic into generate_targets() --- Cargo.lock | 6 +++--- src/cargo/ops/cargo_compile.rs | 38 +++++++--------------------------- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f5e59849d..fda1b5725 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,7 +17,7 @@ dependencies = [ "hamcrest 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.48 (registry+https://github.com/rust-lang/crates.io-index)", @@ -161,7 +161,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libgit2-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -205,7 +205,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libgit2-sys" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cmake 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 1658a1a1b..97a7f499a 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -138,25 +138,6 @@ pub fn resolve_dependencies<'a>(root_package: &Package, Ok((packages, resolved_with_overrides)) } -fn validate_target(package: &Package, - name: &str, - kind: TargetKind, - kind_str: &str) -> CargoResult<()> { - let target = package.targets().iter().find(|t: &&Target| { - t.name() == name && *t.kind() == kind - }); - if target.is_none() { - let suggestion = package.find_closest_target(name, kind); - match suggestion { - Some(s) => bail!("no {} target named `{}`\n\nDid you mean `{}`?", - kind_str, name, s.name()), - None => bail!("no {} target named `{}`", kind_str, name), - } - } - - Ok(()) -} - pub fn compile_pkg<'a>(root_package: &Package, source: Option>, options: &CompileOptions<'a>) @@ -176,16 +157,6 @@ pub fn compile_pkg<'a>(root_package: &Package, bail!("jobs must be at least 1") } - if let CompileFilter::Only{bins, examples, ..} = *filter { - for bin in bins { - try!(validate_target(root_package, bin, TargetKind::Bin, "bin")); - } - - for example in examples { - try!(validate_target(root_package, example, TargetKind::Example, "example")); - } - } - let (packages, resolve_with_overrides) = { try!(resolve_dependencies(root_package, config, source, features, no_default_features)) @@ -392,7 +363,14 @@ fn generate_targets<'a>(pkg: &'a Package, }); let t = match target { Some(t) => t, - None => bail!("no {} target named `{}`", desc, name), + None => { + let suggestion = pkg.find_closest_target(name, kind); + match suggestion { + Some(s) => bail!("no {} target named `{}`\n\nDid you mean `{}`?", + desc, name, s.name()), + None => bail!("no {} target named `{}`", desc, name), + } + } }; debug!("found {} `{}`", desc, name); targets.push((t, profile)); -- 2.30.2